﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Chat
{
    public class CmdBinSerializer<InCmd,OutCmd> : CmdSerializer<InCmd,OutCmd>
        where InCmd : Command where OutCmd : Command
    {
        protected BinaryFormatter InFormatter { get; set; }
        protected BinaryFormatter OutFormatter { get; set; }

        public CmdBinSerializer() : base()
        {
            InFormatter = new BinaryFormatter();
            OutFormatter = new BinaryFormatter();
        }

        public override void Serialize(Stream serializationStream, OutCmd command)
        {
            OutFormatter.Serialize(serializationStream, command);
        }

        protected override object Deserialize(Stream serializationStream)
        {
            return InFormatter.Deserialize(serializationStream);
        }
    }
}
